package com.fauks.se.design_mode.责任链模式;

import java.util.ArrayList;
import java.util.List;

public class HandlerManager {
    private static List<Handler> sHandler;

    static {
        //加载所有配置类
        sHandler = new ArrayList<>();
        sHandler.add(new AHandlerImpl());
        sHandler.add(new BHandlerImpl());
        sHandler.add(new CHandlerImpl());

        /**
         *  ServiceLoader<Handler> load = ServiceLoader.load(Handler.class);
         *         Iterator<Handler> iterator = load.iterator();
         *         while (iterator.hasNext()) {
         *             Handler next = iterator.next();
         *             next.execute();
         *         }
         */
    }

    public static void accept(String con) {
        for (Handler handler : sHandler) {
            if (handler.accept(con)) {
                handler.execute();
            }
        }
    }
}
